package com.xiaoluyy.seekbar;

import android.content.Context;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.view.ViewGroup;
import android.view.inputmethod.InputMethodManager;
import android.widget.Button;
import android.widget.EditText;
import android.widget.FrameLayout;
import android.widget.LinearLayout;
import android.widget.RelativeLayout;
import android.widget.TextView;

public class MainActivity extends AppCompatActivity {
    private InputMethodManager imm;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        imm = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
        final FrameLayout frameLayout = (FrameLayout) findViewById(R.id.linear);
        final LinearLayout linearLayout = (LinearLayout) findViewById(R.id.topLayout);
        final EditText button = (EditText) findViewById(R.id.button);
        final TextView cancel = (TextView) findViewById(R.id.cancel);
        final FrameLayout frame = (FrameLayout) findViewById(R.id.frame);
        final RelativeLayout relativeLayout = (RelativeLayout) findViewById(R.id.relative);
        cancel.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                cancel.setVisibility(View.GONE);
                button.clearFocus();

                relativeLayout.requestFocus();
                imm.hideSoftInputFromWindow(button.getWindowToken(), 0);
            }
        });
        button.setOnFocusChangeListener(new View.OnFocusChangeListener() {
            @Override
            public void onFocusChange(View v, boolean hasFocus) {
                if (hasFocus){
                    cancel.setVisibility(View.VISIBLE);
                    frameLayout.setAnimation(AnimationUtil.moveToViewBottom());
                    frameLayout.setVisibility(View.GONE);
                    AnimationUtil.moveTopToViewGone(MainActivity.this,linearLayout);
                }else {
                    frameLayout.setVisibility(View.VISIBLE);
                    frameLayout.setAnimation(AnimationUtil.moveToViewLocation());
                    AnimationUtil.moveTopToViewLocation(MainActivity.this,linearLayout);
                }
            }
        });

    }
}
